//
// Created by liushuai on 2021/1/1.
//

#include "romanToInt.h"
<<<<<<< HEAD:cxx/algorithm/src/romanToInt.cc
int romanToInt(std::string s){
    std::map<char,int> value_map = {{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}};
    int sum_value = 0;
    char first_value;
    int i=0;
    for(;i<s.size()-1;i++){
        if(s[i] == s[i+1])
            sum_value+=value_map.at(s[i]);
        else if(value_map.at(s[i])<value_map.at(s[i+1]))
            sum_value-=value_map[s[i]];
        else
            sum_value +=value_map[s[i]];
    }
    sum_value += value_map.at(s[i]);
    return sum_value;
=======
int romanToInt(std::string s) {
  std::map<char, int> value_map = {{'I', 1},   {'V', 5},   {'X', 10},
                                   {'L', 50},  {'C', 100}, {'D', 500},
                                   {'M', 1000}};
  int sum_value = 0;
  char first_value;
  int i = 0;
  for (; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1])
      sum_value += value_map.at(s[i]);
    else if (value_map.at(s[i]) < value_map.at(s[i + 1]))
      sum_value -= value_map[s[i]];
    else
      sum_value += value_map[s[i]];
  }
  sum_value += value_map.at(s[i]);
  return sum_value;
>>>>>>> dev:cxx/algorithm/common/src/romanToInt.cc
}